﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MBSVO;


namespace MBS.UserControls.ScreenUserControl
{
    public partial class ViewScreenUserControl : System.Web.UI.UserControl
    {

        MBSBLC.BLC screenblc = new MBSBLC.BLC();


        public delegate void RemoveScreenHandler();

        public event RemoveScreenHandler RemoveScreenSuccesull;
        public event RemoveScreenHandler RemoveScreenFailed;

        private bool actionresult;
        public bool Actionresult
        {
            get { return actionresult; }
            set { actionresult = value; }
        }

        
      // private static int CinemaID;
        

        protected void Page_Load(object sender, EventArgs e)
        {
            screenblc = new MBSBLC.BLC();
            if (!IsPostBack)
            {
                CinemaList1.LoadDropDownBox();
                ScreenList.CinemaID = CinemaList1.GetSelectedValue();
                ScreenList1.LoadDropDownBox();
                
                
                if (CheckValuesExistInscreenDropdown())
                {
                    ScreenList.ScreenID = ScreenList1.GetSelectedValue();
                    ScreenList1_ScreenListChanged(ScreenList.ScreenID);
                }
                
            
            }
        

            CinemaList1.CimeListChanged += new CinemaUserControl.CinemaList.CinemaListHandler(CinemaList1_CimeListChanged);
            ScreenList1.ScreenListChanged += new ScreenList.ScreenListHandler(ScreenList1_ScreenListChanged);
        }

        void CinemaList1_CimeListChanged(int SelectedValue)
        {
            ScreenList.CinemaID = SelectedValue;
            ScreenList1.LoadDropDownBox();
            CheckValuesExistInscreenDropdown(); 
        }





        private void Visiblity(bool isVisible)
        {
            Label1.Visible = isVisible;
            Label2.Visible = isVisible;
            Label3.Visible = isVisible;
                             
            Label5.Visible = isVisible;
            Label6.Visible = isVisible;
            Label7.Visible = isVisible;
        }



        void ScreenList1_ScreenListChanged(int SelectedValue)
        {

            ScreenVO screenVO = screenblc.GetScreenByID(ScreenList.CinemaID, SelectedValue);
            Label5.Text = ""+screenVO.CinemaID;
            Label6.Text = ""+screenVO.ScreenNo;
            Label7.Text = ""+screenVO.NumOfSeats;
        }

        protected void DeleteButton1_Click(object sender, EventArgs e)
        {
            try
            {
                actionresult = screenblc.RemoveScreen(CinemaList1.GetSelectedValue(), ScreenList1.GetSelectedValue());
                if (actionresult)
                {
                    ScreenList1.LoadDropDownBox();
                    CheckValuesExistInscreenDropdown(); 
                    RemoveScreenSuccesull();
                    
                }

                else
                {
                    RemoveScreenFailed();
                }
            }

            catch (Exception ex)
            {
                RemoveScreenFailed();
            }
        }

        private bool CheckValuesExistInscreenDropdown()
        {
            if (ScreenList1.DropdownlistSize() >= 1)
            {
                Visiblity(false);
                ScreenList1_ScreenListChanged(ScreenList1.GetSelectedValue());
                return false;
            }

            else
            {
                Visiblity(true);
                return true;
            }
        }

    }
}